package xyj.sparrow.scheduler.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import xyj.sparrow.scheduler.annotation.UserValid;
import xyj.sparrow.scheduler.common.Result;
import xyj.sparrow.scheduler.entity.TaskLog;
import xyj.sparrow.scheduler.service.ITaskLogService;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jim
 * @since 2021-06-05
 */
@RestController
@RequestMapping("/api/v1/task_log")
@CrossOrigin
@Slf4j
public class TaskLogController {
    @Resource
    private ITaskLogService iTaskLogService;

    @PostMapping("/list")
    @UserValid
    public Result<IPage<TaskLog>> listTaskLog(@RequestBody Page<TaskLog> iPage) {
        if (iPage == null) {
            iPage = new Page<>();
        }
        QueryWrapper<TaskLog> query = new QueryWrapper<>();
        if (!iPage.getRecords().isEmpty()) {
            TaskLog taskLog = iPage.getRecords().get(0);
            if (!StrUtil.isBlank(taskLog.getTaskName())) {
                query.like("task_name", taskLog.getTaskName());
            }
        }
        IPage<TaskLog> page = iTaskLogService.page(iPage, query);
        return Result.success(page);
    }

}

